package com.branik.delivery.dao;

import java.util.List;

import com.branik.delivery.model.Pizza;

/**
 * 
 * Pizza DAO
 * 
 * @author EBraga
 * @version 1.0.0
 *
 */

public class PizzaDAO extends GenericDAO implements IPizzaDAO {

	@Override
	public void addPizza(Pizza pizza) {
		getSessionFactory().getCurrentSession().save(pizza);
	}

	@Override
	public void deletePizza(Pizza pizza) {
		getSessionFactory().getCurrentSession().delete(pizza);
	}

	@Override
	public void updatePizza(Pizza pizza) {
		getSessionFactory().getCurrentSession().update(pizza);
	}

	@Override
	public Pizza getPizzaById(int id) {
		List<Pizza> list = getSessionFactory().getCurrentSession()
											.createQuery("from Pizza where id=?")
									        .setParameter(0, id).list();
		return (Pizza)list.get(0);
	}

	@Override
	public List<Pizza> getPizzas() {
		List<Pizza> list = getSessionFactory().getCurrentSession().createQuery("from Pizza").list();
		return list;
	}

}
